package com.manager.user.module.platform.core.service;

import java.util.*;

import com.manager.commons.mybatis.service.GenericService;
import com.manager.user.module.platform.core.dao.PlatformUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.manager.commons.encrypt.md5.MD5;
import com.manager.commons.mybatis.dao.GenericDao;
import com.manager.user.module.platform.core.entity.UserInfo;
import com.manager.core.web.json.AjaxJson;

/**
 * PlatformUserService
 *
 * @author H
 * @version 1.0
 */
@Service
public class PlatformUserService extends GenericService<UserInfo> {

    @Autowired
    private PlatformUserDao jdbcDao;

    @Override
    public GenericDao<UserInfo> getDao() {
        return jdbcDao;
    }


    /**
     * 登录
     *
     * @param account
     * @return
     */
    public UserInfo login(String account) {
        return jdbcDao.login(new HashMap<String, Object>() {
            private static final long serialVersionUID = -4160187128017253623L;
            {
                put("phone", account);
            }
        });
    }


    /**
     * 重置密码
     *
     * @param params
     * @return
     */
    public AjaxJson updatePwd(Map<String, Object> params) {
        if (null != params) {
            String oldPwd = getParamsString(params, "oldPwd");
            String newPwd = getParamsString(params, "newPwd");
            String opwd = MD5.md5(oldPwd);
            String oldPwdf = jdbcDao.findPwd(params);
            if (!opwd.equals(oldPwdf)) {
                return new AjaxJson(0, "原密码输入错误");
            }
            String npwd = MD5.md5(newPwd);
            params.put("pwd", npwd);
            int f = jdbcDao.updatePwd(params);
            return new AjaxJson(f, "密码修改" + ((f > 0) ? "成功" : "失败！"));
        }
        return new AjaxJson("参数错误");
    }

}